import request from '@/utils/request'

/**
 * 发布文章
 * @param {*} param0
 * @returns
 */
const publishArticleAPI = ({
  draft = false,
  title,
  content,
  cover,
  channel_id
}) => {
  return request({
    method: 'post',
    url: '/v1_0/mp/articles',
    params: {
      draft
    },
    data: {
      title,
      content,
      cover,
      channel_id
    }
  })
}

/**
 * 获取文章详情
 * @param {} param0
 * @returns
 */
const getArticleDetailAPI = ({ artId }) => {
  return request({
    method: 'get',
    url: `/v1_0/mp/articles/${artId}`
  })
}

/**
 * 更新文章
 * @param {*} param0
 * @returns
 */
const updateArticleAPI = ({
  artId,
  draft = false,
  title,
  content,
  cover,
  channel_id
}) => {
  return request({
    method: 'put',
    url: `/v1_0/mp/articles/${artId}`,
    params: {
      draft
    },
    data: {
      artId,
      title,
      content,
      cover,
      channel_id
    }
  })
}

// 导出
export {
  publishArticleAPI,
  getArticleDetailAPI,
  updateArticleAPI
}
